<?php
/**
 * 管理员模型类
 * User: ws
 * Date: 2018/7/20
 * Time: 14:44
 */

namespace app\merchant\model;
use think\Model;

class AdminUser extends Model
{
    function initialize()
    {
        parent::initialize();
    }

    function do_login($params){
        if(empty($params['username'])) {
            return FALSE;
        }
        if(empty($params['password'])) {
            return FALSE;
        }
        $map['store_name'] = $params['username'];
        $map['state'] = 1;
        $admin_user = db('store')->where($map)->find();
        
        if(!$admin_user) {
            return FALSE;
        }
        // $admin_user = $admin_user->toArray();
        if($admin_user['store_pass'] !== strtolower(md5($params['password']))) {
            echo 333;
            return FALSE;
        }

        session('admin_user',$admin_user);
        session('store_id',$admin_user['store_id']);
        return $admin_user;
    }

    function edit($params){
        $result = $this->isUpdate(true)->allowField(true)->save($params);
        if($result){
            return true;
        }else{
            return false;
        }
    }

}